home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-25 | 6.0 KB | 130 lines | [TEXT/CCL ] |
- ; (c) Copyright 1990 by University of Massachusetts. All rights reserved.
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; Mr. Suthers created this software under his own initiative while in an
- ; academic relationship with the University of Massachusetts. The above
- ; copyright notice was a condition placed by University lawyers on approval
- ; of distribution of this software by Apple Computer, and is not meant to
- ; imply that this software was created in an employment or "work for hire"
- ; relationship between the University and Mr. Suthers.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; File: Dequeue.lisp
- ; Author: Dan Suthers
- ; Created: 25-Jan-90 22:45:33
- ; Modified: 22-Jun-90 01:57:19 (Dan Suthers)
- ; Language: Common Lisp
- ; Package: USER
- ;
- ; Description: Double Ended Queue macros.
- ;
- ; (c) Copyright 1990, by Daniel D. Suthers
- ; Department of Computer and Information Science
- ; University of Massachusetts
- ; Amherst, Massachusetts 01003
- ;
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; I wish to acknowledge the generous support of Beverly Woolf, who obtained
- ; the above grants and encouraged me to pursue my own research interests in
- ; her lab. This work would not have been possible without the resources and
- ; stimulating environment of the Computer and Information Science department.
- ;
- ; Permission to use, modify, and distribute this software is granted subject
- ; to the following restrictions and understandings:
- ; 1. The file header, including this notice, shall be retained, and may be
- ; extended to include documentation of modifications to the software.
- ; 2. This material is for nonprofit educational and research purposes only.
- ; Users are requested, but not required, to inform Mr. Suthers of any
- ; noteworthy uses of this software.
- ; 3. Mr. Suthers and the University of Massachusetts make no warrantee or
- ; representation that the operation of this software will be error free,
- ; and are under no obligation to provide any services.
- ; 4. Any user of such software agrees to indemnify and hold harmless Mr.
- ; Suthers and the University of Massachusetts from all claims arising
- ; out of the use or misuse of this software, or arising out of any
- ; accident, injury, or damage whatsoever, and from all costs, counsel
- ; fees, and liabilities incurred in or about any such claim, action, or
- ; proceeding brought thereon.
- ; 5. All materials and reports developed as a consequence of the use of
- ; this software shall duly acknowledge such use, in accordance with
- ; the usual standards of acknowledging credit in academic research.
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package :UTILS)
-
- (export '(
- dequeue-contents
- init-dequeue
- pop-dequeue
- push-dequeue
- queue-dequeue
- sort-dequeue
- top-dequeue
- ))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defmacro INIT-DEQUEUE (place &optional (contents nil))
- "init-dequeue <place> &optional <contents>
- Setf's <place> to a fresh dequeue which is empty or contains the optionally
- provided <contents>. Returns the contents."
- `(let ((the-contents ,contents))
- (setf ,place (cons the-contents (last the-contents)))
- (car ,place)))
-
- (defmacro DEQUEUE-CONTENTS (dequeue)
- "dequeue-contents <dequeue> - returns actual (uncopied) list of contents."
- `(car ,dequeue))
-
- (defmacro TOP-DEQUEUE (dequeue)
- "top-dequeue <dequeue> - returns the first item on <dequeue>, if any,
- without removing it. NIL is returned if there is nothing in the dequeue."
- `(car (car ,dequeue)))
-
- (defmacro PUSH-DEQUEUE (item dequeue)
- "push-dequeue <item> <dequeue> - pushes <item> on the dequeue, returning
- the dequeue's new contents."
- `(progn (setf (car ,dequeue) (cons ,item (car ,dequeue)))
- ;; Make previously empty dequeue point to single entry from both ends.
- (if (null (cdr ,dequeue)) (setf (cdr ,dequeue) (car ,dequeue)))
- ;; Return contents.
- (car ,dequeue)))
-
- (defmacro POP-DEQUEUE (dequeue)
- "pop-dequeue <dequeue> - removes and returns the first item on <dequeue>,
- if any, returning NIL otherwise."
- `(prog1 (car (car ,dequeue))
- (setf (car ,dequeue) (cdr (car ,dequeue)))
- (if (null (car ,dequeue)) (setf (cdr ,dequeue) nil))))
-
- (defmacro QUEUE-DEQUEUE (item dequeue)
- "queue-dequeue <item> <dequeue> - queues <item> on the end of <dequeue>,
- returning the new list of contents."
- `(if (dequeue-contents ,dequeue)
- (let ((new-entry (cons ,item nil)))
- (declare (cons new-entry))
- ;; Set the pointer out of the last cell to the new cell.
- (setf (cdr (cdr ,dequeue)) new-entry)
- ;; Set the last-cell pointer of the dequeue to the new cell.
- (setf (cdr ,dequeue) new-entry)
- ;; Return contents.
- (car ,dequeue))
- ;; empty queue: push is equivalent.
- (push-dequeue ,item ,dequeue)))
-
- (defmacro SORT-DEQUEUE (dequeue predicate)
- "sort-dequeue <dequeue> <predicate> - sorts contents according to <predicate>."
- `(init-dequeue ,dequeue
- (sort (dequeue-contents ,dequeue) ,predicate)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (provide :dequeue)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; The End.